trigger: none

pr:
  branches:
    include:
    - "*"

schedules:
- cron: "0 13 * * *" # 1PM UTC => 5 AM PST
  displayName: SslStress nightly run
  branches:
    include:
    - main
    - release/6.0
    - release/7.0
    - release/8.0

variables:
  - template: ../variables.yml
  - name: dockerfilesFolder
    value: $(Build.SourcesDirectory)/eng/docker
  - name: sslStressProject
    value: $(sourcesRoot)/System.Net.Security/tests/StressTests/SslStress
  - name: sdkBaseImage
    value: dotnet-sdk-libraries-current


extends:
  template:  /eng/pipelines/common/templates/pipeline-with-resources.yml
  parameters:
    stages:
    - stage: Build
      jobs:

      - job: linux
        displayName: Docker Linux
        timeoutInMinutes: 120
        pool:
          name: $(DncEngPublicBuildPool)
          demands: ImageOverride -equals Build.Ubuntu.2204.Amd64.Open

        steps:
        - checkout: self
          clean: true
          fetchDepth: 5

        - bash: |
            $(dockerfilesFolder)/build-docker-sdk.sh -t $(sdkBaseImage) -c $(BUILD_CONFIGURATION)
          displayName: Build CLR and Libraries

        - bash: |
            $(sslStressProject)/run-docker-compose.sh -o -c $(BUILD_CONFIGURATION) -t $(sdkBaseImage)
          displayName: Build SslStress

        - bash: |
            cd '$(sslStressProject)'
            docker-compose up --abort-on-container-exit --no-color
          displayName: Run SslStress

      - job: windows
        displayName: Docker NanoServer
        timeoutInMinutes: 120
        pool:
          name: $(DncEngPublicBuildPool)
          demands: ImageOverride -equals 1es-windows-2022-open
        variables:
          # The 1es-windows-2022-open image has an issue where the Chocolatey-installed V1 docker-compose takes precendence over the
          # V2 docker-compose required by the stress tests, see: https://github.com/actions/runner-images/issues/7080
          # This is worked around by handpicking the V2 executable.
          # The workaround should be removed when the official fix is propagated into 1es-windows-2022-open, or when we switch to another image.
          DOCKER_COMPOSE_CMD: "C:/ProgramData/docker/cli-plugins/docker-compose.exe"
        steps:
        - checkout: self
          clean: true
          fetchDepth: 5
          lfs: false

        - powershell: |
            # Workaround for https://github.com/microsoft/azure-pipelines-agent/issues/4554. Undo when the image bug is fixed.
            Remove-Item -Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\Microsoft.VCToolsVersion.v143.default.txt"

            $(dockerfilesFolder)/build-docker-sdk.ps1 -w -t $(sdkBaseImage) -c $(BUILD_CONFIGURATION)
          displayName: Build CLR and Libraries

        - powershell: |
            $(sslStressProject)/run-docker-compose.ps1 -w -o -c $(BUILD_CONFIGURATION) -t $(sdkBaseImage)
          displayName: Build SslStress

        - powershell: |
            cd '$(sslStressProject)'
            & $env:DOCKER_COMPOSE_CMD up --abort-on-container-exit --no-color
          displayName: Run SslStress
